package org.itboys.core.service.mongo.front;

import org.itboys.admin.entity.lasted.SystemDictionary;
import org.itboys.admin.service.lasted.SystemDictionaryService;
import org.itboys.core.entity.mongo.SundayWeatherRecord;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/21
 * Description:
 */
@Service
public class SundayFrontWeatherRecordService extends BaseMongoService<SundayWeatherRecord> {
    @Autowired
    private SystemDictionaryService dictionaryService;

    @Resource(name = "mobileDs")
    private MongoDataSource mongoDataSource;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return mongoDataSource;
    }

    @Override
    protected Class<SundayWeatherRecord> getEntityClass() {
        return SundayWeatherRecord.class;
    }

    /**
     * 保存天气记录
     *
     * @param weather
     */
    public void save(SundayWeatherRecord weather) {
        super.save(weather);
    }

    /**
     * 查询所有天气类型
     *
     * @return
     */
    public List<String> getWeatherType() {
        List<String> list = new ArrayList<>();

        //组装标签
        List<SystemDictionary> dictionaries = dictionaryService.getDictionaryByKey("weatherType");

        for (SystemDictionary systemDictionary : dictionaries) {
            list.add(systemDictionary.getName());
        }
        return list;
    }

}
